<!DOCTYPE html>
<html lang="en">
<head>
    <title>login</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="./css/style.css" type="text/css" />
    <link rel="stylesheet" href="./layui/css/layui.css">
</head>
<body>
<section class="w3l-login">
    <div class="overlay">
        <div class="wrapper">
            <div class="form-section">
                <h3>登录</h3>
                <h6>登录就能查询</h6>
                <form action="" class="layui-form" lay-filter="example">
                    <div class="form-input">
                        <input type="text" name="name" lay-verify="title"  placeholder="用户名" required="" autofocus>
                    </div>
                    <div class="form-input">
                        <input type="password" name="password" placeholder="密码" required="">
                    </div>
                    <div class="form-input" style="display: block">
                        <input type="text" name="yzm" lay-verify="title" placeholder="验证码" required="" style="width: 150px">
                        <img src="/captcha" width="140px" height="50px"  id="cap"/>
                    </div>
                    <button type="submit" class="btn btn-primary theme-button mt-4" lay-submit="" lay-filter="loginbtn">登录</button>
                </form>
                <p class="signup">还没有账户? <a href="/regist.html" class="signuplink">注册</a></p>
            </div>
        </div>
    </div>
    <div id='stars'></div>
    <div id='stars2'></div>
    <div id='stars3'></div>

    <!-- copyright -->
    <div class="copy-right">
        <p>&copy;版权所有Java2103王浩 <a href="http://w3layouts.com/" target="_blank">W3Layouts</a></p>
    </div>
    <!-- //copyright -->
</section>

<!-- /login form -->
<script src="./layui/layui.js"></script>
<script type="text/javascript">
    layui.use(function () {

        var layer = layui.layer
            , form = layui.form
            , $ = layui.$;
        form.on('submit(loginbtn)', function (data) {
            // layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // });
            $.ajax({
                url: "/user/login",
                type: "post",
                data: data.field,
                success: function (result) {
                    console.log(result);
                    if (result.statusCode == "1001") {
                        // 跳转到后台管理系统的主页面中
                        window.location.href = "/index.html";
                    }else {
                        layer.alert(result.message, {
                            title: '登录错误消息'
                        });
                    }
                }
            });

            return false; // 取消表单的默认提交行为
        });

        // 处理验证码点击后更换图片
        $("#cap").click(function () {
            //刷新验证码
            path = $(this).attr("src") + "?" + new Date().getTime();
            $(this).attr("src", path);
        });

    })
</script>
</body>
</html>